from django.shortcuts import render
from django.http import HttpResponse
from .models import Student, Score, Course, Teacher
from django.db.models import *


def index(request):
    # 1.查询平均成绩大于60分的同学的id和平均成绩；
    # rows = Student.objects.annotate(avg_number=Avg('score__number')).filter(avg_number__gt=60).values('id','avg_number')
    # for row in rows:
    #     print(row)
    # r = Score.objects.aggregate(Avg('number'))
    # print(r)

    # 2. 查询所有同学的id、姓名、选课的数量、总成绩；
    # rows = Student.objects.annotate(q = Count('score'),w = Sum('score__number')).values('id','name','q','w')
    # for row in rows:
    #     print(row)

    # 3.查询姓“李”的老师的个数；
    # rows = Teacher.objects.filter(name = '李').count()
    # print(rows)

    #4. 查询没学过“李老师”课的同学的id、姓名；
    # rows = Student.objects.exclude(score__course__teacher__name = '大牛').values('id','name')
    # for i in rows:
    #     print(i)

    # 5.查询学过课程id为1和2的所有同学的id、姓名；



    return HttpResponse('success')
